/***************************************************************************************************
  *Copyright(C),2010-2016,Sumscope
  *FileName	:  SHash.cpp
  *Author	:  scofined.qi
  *Version	:  1.0
  *Date		:  2015/05/21
  *Desc		:  //用于主要说明此程序文件完成的主要功能
  *Relation :  
  *Others	:  //其他内容说明
  *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
  *History	:  //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
  ***************************************************************************************************/
#include "SHash.h"
#include "./internal/SHashAlgorithm.h"

namespace qb{
namespace base{

unsigned int time33Hash(const char *str, int len){
	unsigned int hash = 5381;
	const char* pend = str + len;
	while (str < pend){
		hash += (hash << 5) + (*str++);
	}
	return (hash & 0x7FFFFFFF);
}
unsigned int GetFastHash(const void* input, unsigned int len, unsigned int seed)
{
	return time33Hash((const char *)input, len);
}
unsigned int murMurHash(const void *key, int len)
{
	const unsigned int m = 0x5bd1e995;
	const int r = 24;
	const int seed = 97;
	unsigned int h = seed ^ len;
	// Mix 4 bytes at a time into the hash
	const unsigned char *data = (const unsigned char *)key;
	while (len >= 4)
	{
		unsigned int k = *(unsigned int *)data;
		k *= m;
		k ^= k >> r;
		k *= m;
		h *= m;
		h ^= k;
		data += 4;
		len -= 4;
	}
	// Handle the last few bytes of the input array
	switch (len)
	{
	case 3: h ^= data[2] << 16;
	case 2: h ^= data[1] << 8;
	case 1: h ^= data[0];
		h *= m;
	};
	// Do a few final mixes of the hash to ensure the last few
	// bytes are well-incorporated.
	h ^= h >> 13;
	h *= m;
	h ^= h >> 15;
	return h;
}

}//namespace base;
}//namespace ss;